<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AJAX_POST</title>
    <style>
        #result {
            width: 200px;
            height: 200px;
            border: 2px solid green;
        }
    </style>
</head>
<body>
    <div id="result"></div>
<script>
    const res = document.getElementById("result");
    res.addEventListener("mouseover", function () {
        const xhr = new XMLHttpRequest();
        xhr.open('POST', 'http://localhost:8080/test2');
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr.send('a=100&b=200');
        //事件绑定
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status < 300) {
                    res.innerHTML = xhr.response;
                }
            }
        }
    });
</script>
</body>
</html>